<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <script>
    //浅拷贝
    const obj={
      uname:'小黑子',
      age:18,
      gender:'男',
      hobbit:['吃','喝','嫖','赌'],
      patner:{
         uname:'小傻子',
         age:17,
         gender:'女',
         hobbit:['逃课','打架','玩']
      }
    }
/*     //1.assign
    const newObj={}
   Object.assign(newObj,obj)
   console.log(newObj); */

/*    //2...
   const newObj={...obj}
   console.log(newObj); */

/*    //3.for in
   const newObj={}
   for(let k in obj){
    newObj[k]=obj[k]
   }
   console.log(newObj); */


   //深拷贝
/*    //1.循环遍历，递归实现
   const newObj={}
   function fn(newObj,oldObj){
    for(let k in oldObj){
      if(oldObj[k] instanceof Array){
        newObj[k]=[]
        fn(newObj[k],oldObj[k])
      }
      else if(oldObj[k] instanceof Object){
        newObj[k]={}
        fn(newObj[k],oldObj[k])
      }
      else{
        newObj[k]=oldObj[k]
      }
    }
   }
  
   fn(newObj,obj)
   console.log(newObj); */

/*   //2.JSON
  const newObj=JSON.parse(JSON.stringify(obj)) 
   console.log(newObj); */
  </script>
</body>
</html>